/*   1:    */ package com.atomikos.datasource.xa.jms;
/*   2:    */ 
/*   3:    */ import com.atomikos.datasource.ResourceException;
/*   4:    */ import com.atomikos.datasource.xa.XATransactionalResource;
/*   5:    */ import com.atomikos.datasource.xa.XidFactory;
/*   6:    */ import java.util.Stack;
/*   7:    */ import javax.jms.JMSException;
/*   8:    */ import javax.jms.XAConnection;
/*   9:    */ import javax.jms.XAConnectionFactory;
/*  10:    */ import javax.jms.XASession;
/*  11:    */ import javax.transaction.xa.XAResource;
/*  12:    */ 
/*  13:    */ public class JmsTransactionalResource
/*  14:    */   extends XATransactionalResource
/*  15:    */ {
/*  16:    */   private XAConnectionFactory factory_;
/*  17:    */   private XAConnection conn_;
/*  18:    */   
/*  19:    */   public JmsTransactionalResource(String name, XAConnectionFactory factory)
/*  20:    */   {
/*  21: 65 */     super(name);
/*  22: 66 */     this.factory_ = factory;
/*  23: 67 */     this.conn_ = null;
/*  24:    */   }
/*  25:    */   
/*  26:    */   public JmsTransactionalResource(String name, XAConnectionFactory qFactory, XidFactory xidFactory)
/*  27:    */   {
/*  28: 86 */     super(name, xidFactory);
/*  29: 87 */     this.factory_ = qFactory;
/*  30: 88 */     this.conn_ = null;
/*  31:    */   }
/*  32:    */   
/*  33:    */   protected synchronized XAResource refreshXAConnection()
/*  34:    */     throws ResourceException
/*  35:    */   {
/*  36:100 */     XAResource res = null;
/*  37:102 */     if (this.conn_ != null) {
/*  38:    */       try
/*  39:    */       {
/*  40:104 */         this.conn_.close();
/*  41:    */       }
/*  42:    */       catch (Exception err) {}
/*  43:    */     }
/*  44:    */     try
/*  45:    */     {
/*  46:113 */       this.conn_ = this.factory_.createXAConnection();
/*  47:114 */       XASession session = this.conn_.createXASession();
/*  48:    */       
/*  49:    */ 
/*  50:    */ 
/*  51:118 */       res = session.getXAResource();
/*  52:    */     }
/*  53:    */     catch (JMSException jms)
/*  54:    */     {
/*  55:120 */       Stack errors = new Stack();
/*  56:121 */       errors.push(jms);
/*  57:122 */       throw new ResourceException("Error in getting XA resource", errors);
/*  58:    */     }
/*  59:126 */     return res;
/*  60:    */   }
/*  61:    */   
/*  62:    */   public void close()
/*  63:    */     throws ResourceException
/*  64:    */   {
/*  65:137 */     super.close();
/*  66:    */     try
/*  67:    */     {
/*  68:139 */       if (this.conn_ != null) {
/*  69:140 */         this.conn_.close();
/*  70:    */       }
/*  71:    */     }
/*  72:    */     catch (JMSException err)
/*  73:    */     {
/*  74:142 */       throw new ResourceException(err.getMessage());
/*  75:    */     }
/*  76:    */   }
/*  77:    */ }


/* Location:           C:\myfile\mysoft\apache-maven-3.5.0-bin\apache-maven-3.5.0\myrep\com\atomikos\transactions-jta\3.7.0\transactions-jta-3.7.0.jar
 * Qualified Name:     com.atomikos.datasource.xa.jms.JmsTransactionalResource
 * JD-Core Version:    0.7.0.1
 */